﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public class AB50MSUMReport : BaseReport
    {
        string strCompany = "HLT";
        string strExcelFile = "";
        string sheetName = "";
        string Standard = "AB50MSUM";
        string filePath = @"C:\intex.w\Report\HLT\HLTProduction.xls";
        public AB50MSUMReport()
            : base()
        {
        }
        public AB50MSUMReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        {
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            strExcelFile = @"HLT\HLTProduction.xls"; 
            #region Excel  columns
             columns.Add("ARTICLE"); 
            #endregion
        }
        public void FillInExcelData(ArrayList columns, DataSet setSoruce, int xStart = 2, int yStart = 1)
        {
            try
            {
                int x = xStart, y = yStart;
                DataTable dtSoruce = setSoruce.Tables["AB50OUTPUT"];
                string suppliercode;
                string ABPPOSTYP;
                double SUBQTY, SUBYIELDQTY;
                int BATCHES;
                string SUMMONTH,SUMYEAR;
                for (int iY = 3; iY < 15; iY++)
                {
                    suppliercode = exAgent.GetCellValue(xStart-2, iY).ToString();
                    var query = from DataRow dwTemp in dtSoruce.AsEnumerable()
                                where dwTemp["LSLIEFNR"].ToString() == suppliercode
                                select dwTemp;
                    foreach (DataRow dwTemp in query)
                    {
                        SUMYEAR = dwTemp["SUMYEAR"].ToString();
                        SUMMONTH = dwTemp["SUMMONTH"].ToString();
                        exAgent.SetCellValue(1, 2, SUMYEAR+"年"+SUMMONTH+"月"); 
                        exAgent.SetCellValue(4, iY, dwTemp["SUBQTY"].ToString()); 
                        exAgent.SetCellValue(6, iY, dwTemp["SUBYIELDQTY"].ToString()); 
                        exAgent.SetCellValue(14, iY, dwTemp["BATCHES"].ToString());  
                        exAgent.SetCellValue(8, iY, dwTemp["G10KGORDERS"].ToString());
                        exAgent.SetCellValue(9, iY, dwTemp["LOTDORDERS"].ToString());
                        exAgent.SetCellValue(10, iY, dwTemp["MAXLESSDAYS"].ToString());
                        exAgent.SetCellValue(11, iY, dwTemp["OTDORDERS"].ToString());
                        exAgent.SetCellValue(12, iY, dwTemp["GOTDORDERS"].ToString());
                        exAgent.SetCellValue(13, iY, dwTemp["MAXDELAYDAYS"].ToString());                  
                    }
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
      
        public override void WriteExcelReport(string fileType)
        {
            string filename = "";
            string sheetName = "";
            string Standard = "AB50OUTPUT";
            strExcelFile = @"HLT\HLTProduction.xls";
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            string filedate = DateTime.Now.Year.ToString();
            filename = @"Production\染纱\染纱月份统计" + filedate + ".xls";
            sheetName =Right("00"+DateTime.Now.Month.ToString(),2)+"月份";
            exAgent.CreateNewSheet(filename, Standard, sheetName);
            FillInExcelData(columns, dsSource, 4, 1);
            base.WriteExcelReport(fileType);
        }
    }
}
